const hook1 = (params, next) => {
  console.log('1');
  setTimeout(() => {
    console.log('1-1');
    next();
    console.log('1-2');
  }, 1000);
};

const hook2 = (params, next) => {
  console.log('2');
  next(false);
};

const hook3 = (params, next) => {
  console.log('3');
  next(false);
};

const runHooks = (hooks, params, cb) => {
  // 实现
  let index = 0;
  const next = (bool = true) => {
    index++;
    console.log('index', index);
    if (index >= hooks.length) return;
    if (bool) {
      hooks[index]({}, next);
    } else {
      cb(bool);
    }
  };
  hooks[index]({}, next);
};

runHooks([hook1, hook2, hook3], {}, (result) => {
  console.log('done', result);
});

/* 输出顺序：
1
1-1 // 1s之后
2
done, false
1-2
*/
